import React,{Component} from 'react'

import {ListStyle} from  './Style'
import tx from 'images/my/touxiang1@3x.png'
import tx2 from 'images/my/touxiang2@3x.png'
import A from 'assets/images/my/denglutouxiang@2x.png'
import UIButton from 'components/UIButton/UIButton'
import Progress from 'components/Progressbar/Progressbar'
import {userData} from 'userData/userData'
import connect from 'pages/redux-component/connect'

import qs from "qs";
import {
    Route,
    withRouter,
  } from 'react-router-dom'

class Line extends Component{
    state={
        title:'',
        cateList:{}
    }
    render(){
        // let aa= this.props.data.data
        // aa=JSON.stringify(aa)
        // aa=JSON.parse(aa)
        console.log(this.state.cateList)
      
        let tag = this.props.match
        console.log(tag)
        return(
            <ListStyle onClick={()=>this.props.handleClick()}>
                <div className="image">
                    <img src={this.state.cateList.himg ? 'http://laienli.cn:8080/Legang'+ this.state.cateList.himg : A} alt=""/>
                </div>
                <div className="right">
                    <div className="first">
                        <p className="name">{this.props.data.uname?this.props.data.uname||'匿名':'匿名'}</p>
                        <div className="reward">赏金￥<p>{this.props.data.task.price}</p></div>
                    </div>
                    <div className="second">
                        <p className="grade">Lv.1</p>
                        <Progress
                            width='1rem'
                            height= '.08rem'
                            borderRadius = '.02rem'
                            progressWidth='80%'
                            progressColor = '#56D9D1'
                        ></Progress>
                    </div>
                    <div className="third">
                        <p>{this.props.data.task.tname}</p>
                        <div className="qiangdan">
                            <p className="ren">{this.props.robbing}</p>
                            {/* <img src={tx2} alt=""/> */}
                            <UIButton
                                title={this.state.title}
                                width='.6rem'
                                height='.2rem'
                                borderRadius='.05rem'
                                backgroundColor = "#FFB538"
                                titleColor='#fff'
                                titleSize = '.12rem'
                                margin='0 0 0 .15rem'
                                clickButton = {()=>this.onClickbtn()}
                            ></UIButton>
                        </div>
                    </div>
                </div>
            </ListStyle>
        )
    }
    componentDidMount(){
        if(this.props.data.task.tstatus === 3){
            this.setState({title :"抢单中"})
        }else if(this.props.data.task.tstatus === 1){
            this.setState({title :"未完成"})
        }else if(this.props.data.task.tstatus === 2){
            this.setState({title :"已完成"})
        }
        let result = fetch('/Legang/user/myface',{
        
            method:"POST",
            headers:{
                "Content-type":"application/x-www-form-urlencoded"
            },
            body: qs.stringify({uid:this.props.data.uid})
            // "email=1486960462@qq.com&password=123456",
            })
            
            .then(response => response.json())
            .then(result => {
                if(result.flag){
                    this.setState({
                        cateList: result.data
                    })
                }
            })
    }
   
    onClickbtn(tag){
        let tstatus = this.props.data.tstatus
        if(tstatus < 2){
           tstatus++
        }
    }
}

export default withRouter(connect(Line))